﻿using System;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Extensions.UnitTests.FuncExtensionsTests
{
    [TestClass]
    public class ExecuteTests
    {
        [TestMethod]
        public void Execute_calls_the_defined_function_and_correctly_returns_the_result()
        {
            const int expectedResult = 1;
            var functionIsCalled = false;

            Func<int> getOne = () =>
                                   {
                                       functionIsCalled = true;
                                       return expectedResult;
                                   };

            var result = getOne.Execute();

            Assert.IsTrue(functionIsCalled);
            Assert.AreEqual(expectedResult, result);
        }

        [TestMethod]
        public void Execute_returns_a_result_that_can_be_extended()
        {
            const int expectedwordCount = 66;

            var getSentence = GetSentence(expectedwordCount);

            var result = getSentence
                .Execute()
                .GetWords();

            Assert.AreEqual(expectedwordCount, result.Count());
        }

        static Func<string> GetSentence(int wordCount)
        {
            var sb = new StringBuilder();

            for (var i = 0; i < wordCount; i++)
            {
                sb.Append(string.Format("word{0} ", i));
            }

            return () => sb.ToString();
        }
    }
}